﻿namespace Votations.NSurvey.SQLServerDAL
{
    using Microsoft.ApplicationBlocks.Data;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Runtime.InteropServices;
    using Votations.NSurvey.Data;
    using Votations.NSurvey.IDAL;

    /// <summary>
    /// SQL Server DAL implementation.
    /// </summary>
    public class SurveyAsset : ISurveyAsset
    {

        public SurveyAssetData GetAllSurveyAssets(int surveyId)
        {
            SurveyAssetData surveyAssetData = new SurveyAssetData();

            SqlHelper.FillDataset(SqlHelper.DbConnectionString, CommandType.StoredProcedure, "vts_spSurveyAssetGetAll", surveyAssetData, new string[] { "SurveyAsset" });

            return surveyAssetData;
        }

        public void SurveyAssetAdd(int surveyId,string assetType,string name)
        {
            SqlParameter[] spParameters = new SqlParameter[3];
            spParameters[0] = new SqlParameter("@SurveyId", surveyId);
            spParameters[1] = new SqlParameter("@AssetType",  assetType);

            spParameters[2] = new SqlParameter("@Name",name);
            SqlHelper.ExecuteNonQuery(SqlHelper.DbConnectionString, "vts_spSurveyAssetAddNew", spParameters);
            
        }

        public void SurveyAssetDelete(int assetId)
        {            
            SqlParameter[] spParameters = new SqlParameter[1];
			spParameters[0]	 = new SqlParameter("@AssetId", assetId);
			
            SqlHelper.ExecuteNonQuery(SqlHelper.DbConnectionString, "vts_spSurveyAssetDelete", spParameters);
        }
    }
}